package com.meessiom.train.crm.product.service;

import com.meessiom.train.crm.product.model.Product;

import com.meessiom.train.crm.product.repository.ProductRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;



@Service
public class ProductService {
    @Autowired
    private ProductRepository productRepository;

    private ProductService productService;

    public List<Product> getAllProduct() {

        return productRepository.findAll();
    }

    public Product create(Product product) {
        return productRepository.save(product);
    }


    public List<Product> createAll(List<Product> products) {
        return productRepository.saveAll(products);
    }


    public Product getProductById(long id) {
        return  productRepository.getById(id);
    }

    public void deleteProduct(long id) {

        Product p  = productRepository.getById(id);

        if( null != p )
            productRepository.delete(p);

    }



}
